from selenium import webdriver
import time,random
from selenium.webdriver import ActionChains, Keys
from selenium.webdriver.support.select import Select

def get_driver():

    driver = webdriver.Edge()
    driver.implicitly_wait(5)
    driver.maximize_window()
    return driver
def input(element, value):
    element.click()
    element.clear()
    element.send_keys(value)
def select_random_first(element):
    options_count = len(Select(element).options)
    random_index = random.randint(1, options_count-1)
    Select(element).select_by_index(random_index)



if __name__ == '__main__':
    driver = get_driver()
    driver.get('http://localhost:8080/YunDuanBoss/login')
    uname = driver.find_element('name', 'userName')
    input(uname, 'YDHR000')
    upass = driver.find_element('name', 'userPass')
    input(upass, 'yunduan123')
    driver.find_element('css selector', '#form-login > div > div > div.modal-footer > button').click()
    time.sleep(3)
# 班级管理
    driver.get('http://localhost:8080/YunDuanBoss/stuClass')
    driver.find_element('css selector','#cmDiv > div.col-lg-12.col-md-12.col-sm-12.col-xs-12.con-body-padding.text-left > button').click()
    # 输入班号
    class_code = driver.find_element('css selector','#addClass-form > div > div:nth-child(1) > input')
    input(  class_code,'YDHRC')
    time.sleep(3)
    # 随机选择方向
    stuClass_drict = driver.find_element('css selector','#addClass-form > div > div:nth-child(2) > select')
    select_random_first(stuClass_drict )
    time.sleep(3)
    # 开班时间
    # ActionChains(driver).send_keys(Keys.DOWN).perform()
    # time.sleep(2)
    # ActionChains(driver).send_keys(Keys.ENTER).perform()
    # time.sleep(2)
    # driver.find_element('css selector','body > div.datetimepicker.datetimepicker-dropdown-bottom-right.dropdown-menu > div.datetimepicker-days > table > tfoot > tr:nth-child(1) > th').click()
    # 随机班主任
    stuClass_teacher = driver.find_element('css selector','#addClass-form > div > div:nth-child(4) > select')
    select_random_first(stuClass_teacher)
    time.sleep(3)
    # 保存
    driver.find_element('css selector','#addClass-modal > div > div > div.modal-footer > button').click()